package code.example.base.collection.queue.blockingqueue;

import code.example.base.collection.queue.Person;
import code.example.tool.LogFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.DelayQueue;

public class TestArrayBlockingQueue {
    public void test() throws InterruptedException{
        BlockingQueue<Person> queue =new ArrayBlockingQueue<Person>(90);

        for(int i=0;i<100;i++){
            Person person =new Person();
            person.setName("N-"+i);
            person.setMoney(i*100);
            if( !queue.offer(person)){
                LogFactory.getLog().info("offer "+person.getName()+" fail");
                try {
                    queue.add(person);
                }catch (Exception  e){
                    LogFactory.getLog().info("add "+person.getName()+" exception");
                }
            }
        }
        Person person ;
        while( (person= queue.poll()) != null){
            LogFactory.getLog().info("poll:"+person.toString());
        }

    }


    public static void main(String [] args){
        try {
            new TestArrayBlockingQueue().test();
        }catch (Exception e){
            LogFactory.getLog().error(e);
        }
    }
}
